<template>
  <div class="right-top" ref="target"></div>
</template>

<script setup>
import { onMounted, ref, watch, defineProps } from "vue";
import * as echarts from "echarts";
const props = defineProps({
  dict_unusualDetail: {
    type: Array,
  },
  dict_unusualCopy: {
    type: Array,
    required: true,
  },
  file_id_show: {
    type: Array,
  },
});
const newData = {
  xAxis: [],
  yAxis: [],
};

let seriesData = [];
let colorArr = ["#8E35FF", "#FFB933", "#44C558", "#2F8FFF"];

seriesData = props.dict_unusualDetail.map((item1, index1) => {
  return {
    min: 230,
    max: 235,
    name: props.file_id_show[index1],
    type: "line",
    symbol: "circle",
    symbolSize: 6,
    itemStyle: {
      color: colorArr[index1],
    },
    lineStyle: {
      width: 4,
    },
    data: item1, // 折线图的数据
  };
});
const target = ref(null);
let mChart = null;
onMounted(() => {
  mChart = echarts.init(target.value);
  renderChart();
});
const renderChart = () => {
  let options = {
    title: {
      text: "异常电压曲线213",
      left: 10,
      top: 10,
      textStyle: {
        color: "#fff",
      },
    },
    grid: {
      containLabel: true,
      bottom: "5%",
      top: "15%",
      left: "6%",
      right: "1%",
    },
    tooltip: {
      trigger: "axis",
      backgroundColor: "rgba(255,255,255,0.1)",
      axisPointer: {
        type: "shadow",
        label: {
          show: true,
          backgroundColor: "#7B7DDC",
        },
      },
      textStyle: {
        color: "white",
      },
    },
    xAxis: {
      triggerEvent: true,
      data: props.dict_unusualDetail[0].map((item, index) => {
        return index;
      }),
      axisLabel: {
        interval: 0,
        show: false,
        fontSize: 12,
        color: "#FFF",
      },
      axisLine: {
        show: false,
        lineStyle: {
          show: false,
          color: "#F3F3F3",
          width: 2,
        },
      },

      axisTick: {
        show: false,
      },
    },
    yAxis: {
      type: "value",
      min: 230,
      max: 245,
      name: "用户电压值",
      nameLocation: "center",
      nameTextStyle: {
        padding: [0, 0, 30, 0],
        color: "white",
      },
    },
    series: seriesData,
  };
  mChart.setOption(options);
};
window.addEventListener("resize", function () {
  mChart.resize();
});
watch(
  () => props.dict_unusualDetail,
  () => {
    renderChart();
  }
);
</script>

<style lang="scss" scoped>
.right-top {
  width: 95%;
  height: 95%;
  padding: 20px;
}
</style>
